<?php

include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');

if (!isEmpty(getParam('operation'))) {
    switch (getParam('operation')) {
        case 's':
            save($db, $user);
            break;
        case 'u':
            update($db);
            break;
        case 'd':
            delete($db);
            break;
    }
}

function save($db, $user) {
    $db->query_insert('cllg_pensum', array(
        'CODE_RELEASE' => sqlValue(getParam('CODE'), 'int'),
        'FK_CAREER' => sqlValue(getParam('FK_CAREER'), 'int'),
        'CYCLES' => sqlValue(getParam('CYCLES'), 'int'),
        'STATUS' => sqlValue('1', 'int'),
        'CREATED_BY' => sqlValue($user->name, 'text'),
        'CREATED' => sqlValue(date("y-m-d"), 'date')));
    echo 'SAVED';
}

function update($db) {
    $db->query_update('cllg_pensum', array(
        'FK_CAREER' => sqlValue(getParam('FK_CAREER'), 'text'),
        'STATUS' => sqlValue(getParam('STATUS'), 'int'),
        'CODE_RELEASE' => sqlValue(getParam('CODE'), 'text')));
    echo 'UPDATED';
}

function delete($db) {
    $db->query_delete('cllg_pensum', 'CODE_RELEASE=' . sqlValue(getParam('CODE'), 'text'));
    echo 'DELETED';
}

?>